package com.ruoyi.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.manage.domain.DeptWorkSchedule;
import com.ruoyi.manage.service.IDeptWorkScheduleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 部门排班Controller
 * 
 * @author cf
 * @date 2025-05-29
 */
@RestController
@RequestMapping("/manage/schedule")
public class DeptWorkScheduleController extends BaseController
{
    @Autowired
    private IDeptWorkScheduleService deptWorkScheduleService;

    /**
     * 查询部门排班列表
     */
    @PreAuthorize("@ss.hasPermi('manage:schedule:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeptWorkSchedule deptWorkSchedule)
    {
        startPage();
        List<DeptWorkSchedule> list = deptWorkScheduleService.selectDeptWorkScheduleList(deptWorkSchedule);
        return getDataTable(list);
    }

    /**
     * 导出部门排班列表
     */
    @PreAuthorize("@ss.hasPermi('manage:schedule:export')")
    @Log(title = "部门排班", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeptWorkSchedule deptWorkSchedule)
    {
        List<DeptWorkSchedule> list = deptWorkScheduleService.selectDeptWorkScheduleList(deptWorkSchedule);
        ExcelUtil<DeptWorkSchedule> util = new ExcelUtil<DeptWorkSchedule>(DeptWorkSchedule.class);
        util.exportExcel(response, list, "部门排班数据");
    }

    /**
     * 获取部门排班详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:schedule:query')")
    @GetMapping(value = "/{workScheduleId}")
    public AjaxResult getInfo(@PathVariable("workScheduleId") Long workScheduleId)
    {
        return success(deptWorkScheduleService.selectDeptWorkScheduleByWorkScheduleId(workScheduleId));
    }

    /**
     * 新增部门排班
     */
    @PreAuthorize("@ss.hasPermi('manage:schedule:add')")
    @Log(title = "部门排班", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeptWorkSchedule deptWorkSchedule)
    {
        return toAjax(deptWorkScheduleService.insertDeptWorkSchedule(deptWorkSchedule));
    }

    /**
     * 修改部门排班
     */
    @PreAuthorize("@ss.hasPermi('manage:schedule:edit')")
    @Log(title = "部门排班", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeptWorkSchedule deptWorkSchedule)
    {
        return toAjax(deptWorkScheduleService.updateDeptWorkSchedule(deptWorkSchedule));
    }

    /**
     * 删除部门排班
     */
    @PreAuthorize("@ss.hasPermi('manage:schedule:remove')")
    @Log(title = "部门排班", businessType = BusinessType.DELETE)
	@DeleteMapping("/{workScheduleIds}")
    public AjaxResult remove(@PathVariable Long[] workScheduleIds)
    {
        return toAjax(deptWorkScheduleService.deleteDeptWorkScheduleByWorkScheduleIds(workScheduleIds));
    }
}
